<!--
 @description 分厂 产线产量图
 @fileName MonthChart.vue
 @author zengqiongying
 @created 2021/09/29 11:16:05
-->
<template>
  <div style="margin-left:-0.27rem;margin-right:-0.27rem;height:260px">
    <div v-show="factoryName && seriesData.length" :id="chartId" ref="myEchart" class="echart_container" />
  </div>
</template>

<script>
import ChartPieMixin from '@/mixins/ChartPie'
import { parseTime } from '@/utils'
import { getCustomizedProductLineRateQuantity } from '@/apis/produces'
export default {
  name: 'CustomizedLineRateChart',
  mixins: [ChartPieMixin],
  props: {
    selectDate: {
      type: String,
      default: parseTime(new Date(), '{y}-{m}-{d}')
    }, // 日期
    factoryName: {
      type: String,
      default: ''
    } // 工厂类型
  },
  data() {
    return {
      seriesData: [],
      legendData: ['产线占比'] // 图列数据
    }
  },
  watch: {
    selectDate(val, oldVal) {
      this.drawChart()
    },
    factoryName(val, oldVal) {
      this.drawChart()
    }
  },
  created() {

  },
  methods: {
    async getChartData() {
      let seriesData = []
      const params = {
        date: this.selectDate,
        factoryName: this.factoryName
      }
      await getCustomizedProductLineRateQuantity(params).then(res => {
        if (res.data && res.data.length) {
          seriesData = res.data.map(v => {
            return {
              value: v.completedQuantity || 0,
              name: v.productLineName || ''
            }
          })
        }
      })
      this.seriesData = seriesData
      this.chart.chartData.seriesData = [seriesData]
    },
    getRandom(min, max) {
      return Math.floor(Math.random() * (max - min)) + min
    }
  }
}

</script>
<style lang='less' scoped>
  .echart_container{
    height:260px
  }
</style>
